package com.itheima.tanhua.web;


import com.itheima.tanhua.service.CommentService;
import com.itheima.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
//评论
@RestController
@RequestMapping("/comments")
public class CommentController {


    @Autowired
    private CommentService commentService;

    /**
     * 提交评论
     * @param param
     * @return
     */
    @PostMapping
    public ResponseEntity comments(@RequestBody Map<String ,String> param){
        commentService.postComments(param);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    public ResponseEntity commentsList(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                       @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize,
                                       String movementId){

       PageResult pageResult= commentService.commentsList(page,pagesize,movementId);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId) {
        Integer likeCounts = commentService.likeComment(movementId);
        return ResponseEntity.ok(likeCounts);
    }

    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId) {
        Integer likeCounts = commentService.disLikeComment(movementId);
        return ResponseEntity.ok(likeCounts);
    }

    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String movementId) {
        Integer loveCounts = commentService.loveCommment(movementId);
        return ResponseEntity.ok(loveCounts);
    }

    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String movementId) {
        Integer loveCounts = commentService.unloveCommment(movementId);
        return ResponseEntity.ok(loveCounts);
    }

}
